package accessory.crtm;

import java.awt.Dimension;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import map.GameMap;
import map.RasterCell;

public class SerialCRTMWriter implements CRTMWriter {

	@Override
	public void writeToFile(String filename, RasterCell[][] src, int xDimension, int yDimension) throws Exception {
		 FileOutputStream file;
		 file = new FileOutputStream( filename );
	     ObjectOutputStream o = new ObjectOutputStream( file );
	     Dimension rastersize = new Dimension(xDimension, yDimension);
	    
	     o.writeObject(rastersize);

			for(int i = 0 ; i < xDimension; i++){
				for (int j = 0; j < yDimension; j++) {
				     o.writeObject(src[i][j]);
				}
			}
	     
	     o.close();
	}

	@Override
	public void writeToFile(String filename, GameMap src) throws Exception {
		 FileOutputStream file;
		 file = new FileOutputStream( filename );
	     ObjectOutputStream o = new ObjectOutputStream( file );
	    
	     o.writeObject(src);

		
	}

}
